package com.vision.controller;

import com.vision.pojo.AjaxResult;
import com.vision.pojo.vo.CollectContentVO;
import com.vision.pojo.vo.PageVO;
import com.vision.service.UserCollectService;
import org.apache.ibatis.annotations.Delete;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userCollect")
public class UserCollectController {
    @Autowired
    private UserCollectService userCollectService;

    /**
     * 添加收藏视频
     * @param videoId 视频id
     * @return AjaxResult
     */
    @PostMapping("/addCollect")
    public AjaxResult addCollect (@NotNull Integer videoId) {
        userCollectService.addCollect(videoId);
        return AjaxResult.success();
    }

    /**
     * 取消收藏视频
     * @param videoId 视频id
     * @return AjaxResult
     */
    @DeleteMapping("/cancelCollect")
    public AjaxResult cancelCollect (@NotNull Integer videoId) {
        userCollectService.cancelCollect(videoId);
        return AjaxResult.success();
    }

    /**
     * 获取当前用户收藏的视频列表
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param userId 用户id
     * @return 收藏视频列表
     */
    @GetMapping("/getCollectVideoForPage")
    public AjaxResult<PageVO<CollectContentVO>> getCollectVideoForPage(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer userId
    ) {
        PageVO<CollectContentVO> collectContent = userCollectService.getCollectVideoForPage(pageNum,pageSize,userId);
        return AjaxResult.success(collectContent);
    }
}
